package com.example.li.bean;

import android.text.TextUtils;

import cn.bmob.v3.BmobObject;
import cn.bmob.v3.b.Tempest;
import cn.bmob.v3.helper.GsonUtil;
import cn.bmob.v3.http.darkness;
import cn.bmob.v3.http.mine;
import cn.bmob.v3.http.thing;
import cn.bmob.v3.http.bean.R1;
import cn.bmob.v3.http.mine.This;
import cn.bmob.v3.listener.LogInListener;
import cn.bmob.v3.listener.SaveListener;
import cn.bmob.v3.listener.UpdateListener;

import com.google.gson.JsonElement;

import java.lang.reflect.ParameterizedType;
import java.util.Iterator;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import rx.Observable;
import rx.Subscription;
import rx.functions.Action1;
import rx.functions.Func1;

/**
 * Created by li on 2018/4/22.
 */

public class BmobUserSetting extends BmobObject {
   /*    private static final long serialVersionUID = -1589804003600796026L;
    private String username;
    private String password;
    private String email;
    private Boolean emailVerified;
    private String sessionToken;
    private String mobilePhoneNumber;
    private Boolean mobilePhoneNumberVerified;
    static JSONObject current;

    public BmobUserSetting() {
    }

    public String getTableName() {
        return "_User";
    }

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Boolean getEmailVerified() {
        return this.emailVerified;
    }

    public void setEmailVerified(Boolean emailVerified) {
        this.emailVerified = emailVerified;
    }

    public String getSessionToken() {
        return this.sessionToken;
    }

    public void setSessionToken(String sessionToken) {
        this.sessionToken = sessionToken;
    }

    public String getMobilePhoneNumber() {
        return this.mobilePhoneNumber;
    }

    public void setMobilePhoneNumber(String mobilePhoneNumber) {
        this.mobilePhoneNumber = mobilePhoneNumber;
    }

    public Boolean getMobilePhoneNumberVerified() {
        return this.mobilePhoneNumberVerified;
    }

    public void setMobilePhoneNumberVerified(Boolean mobilePhoneNumberVerified) {
        this.mobilePhoneNumberVerified = mobilePhoneNumberVerified;
    }

    public <T> Subscription signOrLogin(String smsCode, SaveListener<T> listener) {
        return this.Code(thing.Code(smsCode, " Verify code can't be empty "), darkness.Code().Code("login_or_signup"), smsCode, listener);
    }

    public <T> Observable<T> signOrLoginObservable(Class<T> clazz, String smsCode) {
        if (clazz == null) {
            throw new IllegalArgumentException(" class must not be null ");
        } else {
            return this.Code(clazz, (List) thing.Code(smsCode, " Verify code can't be empty "), darkness.Code().Code("login_or_signup"), smsCode, (SaveListener) null).Code();
        }
    }

    public <T> Observable<T> signUpObservable(Class<T> clazz) {
        if (clazz == null) {
            throw new IllegalArgumentException(" class must not be null ");
        } else {
            return this.Code(clazz, (List) thing.Code("no check", " no check "), darkness.Code().Code("signup"), (String) null, (SaveListener) null).Code();
        }
    }

    public <T> Subscription signUp(SaveListener<T> listener) {
        return this.Code((List) thing.Code("no check", " no check "), darkness.Code().Code("signup"), (String) null, (SaveListener) listener);
    }

    private <T> mine Code(Class<T> var1, List<R1> var2, String var3, String var4, SaveListener<T> var5) {
        JSONObject var6 = new JSONObject();

        try {
            JSONObject var7 = this.getCurrentData();
            if (!TextUtils.isEmpty(var4)) {
                var7.put("smsCode", var4);
            }

            var6.put("data", var7);
            var6.put("c", this.getTableName());
        } catch (JSONException var8) {
            var8.printStackTrace();
        }

//        return (new This()).Code(var2).Code(var3, var6).Code(new Func1<JsonElement, Object>(this, var1) {
//            {
//                this.V = var1;
//                this.Code = var2;
//            }
//        }).V(var5).C();
    }

    private <T> Subscription Code(List<R1> var1, String var2, String var3, SaveListener<T> var4) {
        if (var4 == null) {
            throw new IllegalArgumentException(" listener must not be null ");
        } else {
            Class var5 = (Class) ((ParameterizedType) var4.getClass().getGenericSuperclass()).getActualTypeArguments()[0];
            return this.Code(var5, var1, var2, var3, var4).V();
        }
    }

    private <T> mine Code(Class<T> var1, SaveListener<T> var2) {
        JSONObject var3 = new JSONObject();

        try {
            JSONObject var4;
            (var4 = new JSONObject()).put("username", this.getUsername());
            var4.put("password", this.password);
            var3.put("data", var4);
            var3.put("c", this.getTableName());
        } catch (JSONException var6) {
            var6.printStackTrace();
        }

//        return (new This()).Code(thing.Code(this.getUsername(), " username can't be empty ", this.password, " password can't be empty ")).Code(darkness.Code().Code("login"), var3).Code(new Action1<JsonElement>(this) {
//        }).Code(new Func1<JsonElement, Object>(this, var1) {
//            {
//                this.V = var1;
//                this.Code = var2;
//            }
//        }).V(var2).C();
    }

    public <T> Subscription login(SaveListener<T> listener) {
        if (listener == null) {
            throw new IllegalArgumentException(" listener must not be null ");
        } else {
            Class var2 = (Class) ((ParameterizedType) listener.getClass().getGenericSuperclass()).getActualTypeArguments()[0];
            return this.Code(var2, listener).V();
        }
    }

    public <T> Observable<T> loginObservable(Class<T> clazz) {
        if (clazz == null) {
            throw new IllegalArgumentException(" class must not be null ");
        } else {
            return this.Code((Class) clazz, (SaveListener) null).Code();
        }
    }

    public Subscription save() {
        throw new IllegalArgumentException(" _User does not support save operation,please use login / signUp method");
    }

    public Subscription save(SaveListener listener) {
        throw new IllegalArgumentException(" _User does not support save operation,please use login / signUp method");
    }

    public Subscription update() {
        return this.update((UpdateListener) null);
    }

    public Subscription update(UpdateListener listener) {
        return this.update(this.getObjectId(), listener);
    }

    private mine Code(String var1, UpdateListener var2) {
//        JSONObject var3 = new JSONObject();
//
//        try {
//            current = new JSONObject(GsonUtil.toJson(this));
//            JSONObject var4;
//            (var4 = this.getCurrentData()).remove("objectId");
//            var4.remove("sessionToken");
//            var4.remove("createdAt");
//            var4.remove("updatedAt");
//            if (increments.size() > 0) {
//                Iterator var5 = increments.iterator();
//
//                while (var5.hasNext()) {
//                    JSONObject var6;
//                    String var7 = (var6 = (JSONObject) var5.next()).optString("key");
//                    var6.remove("key");
//                    var4.put(var7, var6);
//                }
//
//                increments.clear();
//            }

//            var3.put("data", var4);
//            var3.put("c", this.getTableName());
//            var3.put("objectId", var1);
//        } catch (JSONException var8) {
//            var8.printStackTrace();
//        }

//        return (new This()).Code(thing.Code(var1, " objectId can't be empty ")).Code(darkness.Code().Code("update"), var3).Code(new Action1<JsonElement>(this, var1, var3) {
//            {
//                this.Code = var2;
//                this.V = var3;
//            }
//        }).Code(new Func1<JsonElement, Object>(this, var1) {
//            {
//                this.V = var1;
//                this.Code = var2;
//            }
//        }).V(var2).C();
//    }

//    public Observable<Void> updateObservable(String objectId) {
//        return this.Code((String) objectId, (UpdateListener) null).Code();
//    }

        public Subscription update(String objectId, UpdateListener listener) {
            return this.Code(objectId, listener).V();
        }

    private static mine Code(BmobUserSetting.BmobThirdUserAuth var0, LogInListener<JSONObject> var1) {
        JSONObject var2 = var0 == null ? new JSONObject() : var0.toJSONObject();
        JSONObject var3 = new JSONObject();

        try {
            var3.put("data", (new JSONObject()).put("authData", var2));
            var3.put("c", "_User");
        } catch (Exception var5) {
            var5.printStackTrace();
        }

//        return (new This()).Code(thing.Code(var0, "authInfo is null")).Code(darkness.Code().Code("login_or_signup"), var3).Code(new Action1<JsonElement>() {
//        }).Code(new Func1<JsonElement, Object>(var2) {
//            {
//                this.Code = var1;
//            }
//        }).V(var1).C();
//    }

    public static Subscription loginWithAuthData(BmobUserSetting.BmobThirdUserAuth authInfo, LogInListener<JSONObject> listener) {
        return Code(authInfo, listener).V();
    }

    public static Observable<JSONObject> loginWithAuthDataObservable(BmobUserSetting.BmobThirdUserAuth authInfo) {
        return Code((BmobUserSetting.BmobThirdUserAuth) authInfo, (LogInListener) null).Code();
    }

    private static mine Code(BmobUserSetting.BmobThirdUserAuth var0, UpdateListener var1) {
        JSONObject var2 = new JSONObject();

        try {
            JSONObject var3 = new JSONObject();
            var2.put("data", var3.put("authData", var0.toJSONObject()));
            var2.put("c", "_User");
            var2.put("objectId", getCurrentUser().getObjectId());
        } catch (Exception var4) {
            var4.printStackTrace();
        }

        thing.Code();
        return thing.Code(thing.Code(getCurrentUser(), " user must be login before associate ", var0, " authInfo is null"), darkness.Code().Code("update"), var2, var1);
    }

    public static Observable<Void> associateWithAuthDataObservable(BmobUserSetting.BmobThirdUserAuth authInfo, UpdateListener listener) {
        return Code(authInfo, listener).Code();
    }

    public static Subscription associateWithAuthData(BmobUserSetting.BmobThirdUserAuth authInfo, UpdateListener listener) {
        return Code(authInfo, listener).V();
    }

    private static mine V(String var0, UpdateListener var1) {
        JSONObject var2 = new JSONObject();

        try {
            JSONObject var3;
            (var3 = new JSONObject()).put("authData", (new JSONObject()).put(var0, JSONObject.NULL));
            var2.put("data", var3);
            var2.put("c", "_User");
            var2.put("objectId", getCurrentUser().getObjectId());
        } catch (Exception var4) {
            var4.printStackTrace();
        }

        thing.Code();
        return thing.Code(thing.Code(getCurrentUser(), " user must be login before disassociate ", var0, " type  is null"), darkness.Code().Code("update"), var2, var1);
    }

    public Subscription dissociateAuthData(String type, UpdateListener listener) {
        return V(type, listener).V();
    }

    public Observable<Void> dissociateAuthDataObservable(String type) {
        return V(type, (UpdateListener) null).Code();
    }

    private static mine I(String var0, UpdateListener var1) {
        JSONObject var2 = new JSONObject();

        try {
            (var2 = new JSONObject()).put("data", (new JSONObject()).put("email", var0));
            var2.put("c", "_User");
        } catch (JSONException var4) {
            var4.printStackTrace();
        }

        thing.Code();
        return thing.Code(thing.Code(var0, " email  can't be empty"), darkness.Code().Code("email_verify"), var2, var1);
    }

    public static Subscription requestEmailVerify(String email, UpdateListener listener) {
        return I(email, listener).V();
    }

    public static Observable<Void> requestEmailVerifyObservable(String email) {
        return I(email, (UpdateListener) null).Code();
    }

    private static mine Z(String var0, UpdateListener var1) {
        JSONObject var2 = new JSONObject();

        try {
            (var2 = new JSONObject()).put("data", (new JSONObject()).put("email", var0));
        } catch (JSONException var4) {
            var4.printStackTrace();
        }

        thing.Code();
        return thing.Code(thing.Code(var0, " email  can't be empty"), darkness.Code().Code("reset"), var2, var1);
    }

    public static Subscription resetPasswordByEmail(String email, UpdateListener listener) {
        return Z(email, listener).V();
    }

    public static Observable<Void> resetPasswordByEmailObservable(String email) {
        return Z(email, (UpdateListener) null).Code();
    }

    private static mine Code(String var0, String var1, UpdateListener var2) {
        JSONObject var3 = new JSONObject();

        try {
            var3 = new JSONObject();
            JSONObject var4;
            (var4 = new JSONObject()).put("smsCode", var0);
            var4.put("password", var1);
            var3.put("data", var4);
            var3.put("c", "_User");
        } catch (JSONException var5) {
            var5.printStackTrace();
        }

        thing.Code();
        return thing.Code(thing.Code(var0, " Verify code can't be empty", var1, " newPassword can't be empty"), darkness.Code().Code("phone_reset"), var3, var2);
    }

    public static Subscription resetPasswordBySMSCode(String smsCode, String newPassword, UpdateListener listener) {
        return Code(smsCode, newPassword, listener).V();
    }

    public static Observable<Void> resetPasswordBySMSCodeObservable(String smsCode, String newPassword) {
        return Code(smsCode, newPassword, (UpdateListener) null).Code();
    }

    private static <T> mine Code(Class<T> var0, String var1, String var2, LogInListener<T> var3) {
        JSONObject var4 = new JSONObject();

        try {
            JSONObject var5;
            (var5 = new JSONObject()).put("username", var1);
            var5.put("password", var2);
            var4.put("data", var5);
            var4.put("c", "_User");
        } catch (JSONException var6) {
            var6.printStackTrace();
        }

        return thing.Code().Code(var0, thing.Code(var1, " account can't be empty ", var2, " password can't be empty "), darkness.Code().Code("login"), var4, var3);
    }

    public static <T> Subscription loginByAccount(String account, String password, LogInListener<T> listener) {
        if (listener == null) {
            throw new IllegalArgumentException(" listener must not be null ");
        } else {
            return Code((Class) ((ParameterizedType) listener.getClass().getGenericSuperclass()).getActualTypeArguments()[0], account, password, listener).V();
        }
    }

    public static <T> Observable<T> loginByAccountObservable(Class<T> clazz, String account, String password) {
        if (clazz == null) {
            throw new IllegalArgumentException(" class must not be null ");
        } else {
            return Code((Class) clazz, account, password, (LogInListener) null).Code();
        }
    }

    public static <T> Subscription loginBySMSCode(String phoneNumber, String smsCode, LogInListener<T> listener) {
        if (listener == null) {
            throw new IllegalArgumentException(" listener must not be null ");
        } else {
            return Code((Class) ((ParameterizedType) listener.getClass().getGenericSuperclass()).getActualTypeArguments()[0], darkness.Code().Code("login"), phoneNumber, smsCode, listener).V();
        }
    }

    public static <T> Subscription signOrLoginByMobilePhone(String phoneNumber, String smsCode, LogInListener<T> listener) {
        if (listener == null) {
            throw new IllegalArgumentException(" listener must not be null ");
        } else {
            return Code((Class) ((ParameterizedType) listener.getClass().getGenericSuperclass()).getActualTypeArguments()[0], darkness.Code().Code("login_or_signup"), phoneNumber, smsCode, listener).V();
        }
    }

    private static <T> mine Code(Class<T> var0, String var1, String var2, String var3, LogInListener<T> var4) {
        JSONObject var5 = new JSONObject();

        try {
            JSONObject var6;
            (var6 = new JSONObject()).put("mobilePhoneNumber", var2);
            var6.put("smsCode", var3);
            var5.put("data", var6);
            var5.put("c", "_User");
        } catch (JSONException var7) {
            var7.printStackTrace();
        }

        return thing.Code().Code(var0, thing.Code(var2, " phoneNumber can't be empty ", var3, " smsCode can't be empty "), var1, var5, var4);
    }

    public static Subscription updateCurrentUserPassword(String oldPwd, String newPwd, UpdateListener listener) {
        JSONObject var3 = new JSONObject();

        try {
            String var4 = getCurrentUser().getObjectId();
            JSONObject var5;
            (var5 = new JSONObject()).put("oldPassword", oldPwd);
            var5.put("newPassword", newPwd);
            var3.put("data", var5);
            var3.put("objectId", var4);
            var3.put("c", "_User");
        } catch (Exception var6) {
            var6.printStackTrace();
        }

        thing.Code();
        return thing.Code(thing.Code(oldPwd, " oldPassword can't be empty", newPwd, " newPassword can't be empty", getCurrentUser(), "Cannot update user password until it has been logined. Please call login first."), darkness.Code().Code("update_user_password"), var3, listener).V();
    }

    public static <T> T getCurrentUser(Class<T> clazz) {
        return GsonUtil.toObject((new Tempest()).V("user", ""), clazz);
    }

    public static BmobUserSetting getCurrentUser() {
        return (BmobUserSetting) getCurrentUser(BmobUserSetting.class);
    }

    public static void logOut() {
        (new Tempest()).Code("user");
        (new Tempest()).Code("sessionToken");
    }

    public static Object getObjectByKey(String key) {
        String var1 = (new Tempest()).V("user", "");
        Object var2 = null;

        try {
            var2 = (new JSONObject(var1)).opt(key);
        } catch (Exception var3) {
            ;
        }

        return var2;
    }

    public static class BmobThirdUserAuth {
        private String Code;
        private String V;
        private String I;
        private String Z;
        public static final String SNS_TYPE_WEIBO = "weibo";
        public static final String SNS_TYPE_QQ = "qq";
        public static final String SNS_TYPE_WEIXIN = "weixin";

        public BmobThirdUserAuth(String snsType, String accessToken, String expiresIn, String userId) {
            this.V = accessToken;
            this.Code = snsType;
            this.I = expiresIn;
            this.Z = userId;
        }

        protected static String getPlatformIdByType(String type) {
            return !"qq".equalsIgnoreCase(type) && !"weixin".equalsIgnoreCase(type) ? "uid" : "openid";
        }

        public String getAccessToken() {
            return this.V;
        }

        public void setAccessToken(String accessToken) {
            this.V = accessToken;
        }

        public String getUserId() {
            return this.Z;
        }

        public void setUserId(String userId) {
            this.Z = userId;
        }

        public String getExpiresIn() {
            return this.I;
        }

        public void setExpiresIn(String expiresIn) {
            this.I = expiresIn;
        }

        public String getSnsType() {
            return this.Code;
        }

        public void setSnsType(String snsType) {
            this.Code = snsType;
        }

        public JSONObject toJSONObject() {
            JSONObject var1 = new JSONObject();

            try {
                JSONObject var2 = new JSONObject();
                if (!TextUtils.isEmpty(this.Code)) {
                    var2.put(getPlatformIdByType(this.Code), this.Z);
                }

                var2.put("access_token", this.V);
                if ("qq".equalsIgnoreCase(this.Code)) {
                    var2.put("expires_in", Double.parseDouble(this.I));
                } else if ("weibo".equalsIgnoreCase(this.Code)) {
                    var2.put("expires_in", Long.parseLong(this.I));
                } else {
                    var2.put("expires_in", Long.parseLong(this.I));
                }

                var1.put(this.Code, var2);
            } catch (JSONException var3) {
                ;
            }

            return var1;
        }
    }
*/
}
